IF(NOT UUID_NAMESPACE)
  SET(UUID_NAMESPACE "UUID")
  SET(UUID_STANDALONE 1)
ENDIF(NOT UUID_NAMESPACE)
# In all cases:
STRING(TOLOWER ${UUID_NAMESPACE} UUID_LIBRARY_NAME)

PROJECT(${UUID_NAMESPACE} C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.2)

# Do full dependency headers.
INCLUDE_REGULAR_EXPRESSION("^.*$")

SET(UUID_SRCS
compare.c
gen_uuid.c
pack.c
parse.c
unpack.c
unparse.c
uuid_time.c
uuid.h
uuidP.h
)

#INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)

IF(WIN32)
  IF (BUILD_SHARED_LIBS)
    ADD_DEFINITIONS(-DUUID_DLL)
  ENDIF (BUILD_SHARED_LIBS)
ENDIF(WIN32)


CHECK_INCLUDE_FILE_CONCAT("stdlib.h"       HAVE_STDLIB_H)
IF(UNIX) #Avoid polluting Win32 cmakecache
  CHECK_INCLUDE_FILE_CONCAT("unistd.h"       HAVE_UNISTD_H)
  CHECK_INCLUDE_FILE_CONCAT("inttypes.h"     HAVE_INTTYPES_H)
  CHECK_INCLUDE_FILE_CONCAT("sys/ioctl.h"    HAVE_SYS_IOCTL_H)
  CHECK_INCLUDE_FILE_CONCAT("sys/time.h"     HAVE_SYS_TIME_H)
  CHECK_INCLUDE_FILE_CONCAT("sys/file.h"     HAVE_SYS_FILE_H)
  CHECK_INCLUDE_FILE_CONCAT("sys/socket.h"   HAVE_SYS_SOCKET_H)
  CHECK_INCLUDE_FILE_CONCAT("sys/sockio.h"   HAVE_SYS_SOCKIO_H)
  CHECK_INCLUDE_FILE_CONCAT("net/if.h"       HAVE_NET_IF_H)
  CHECK_INCLUDE_FILE_CONCAT("netinet/in.h"   HAVE_NETINET_IN_H)
  CHECK_INCLUDE_FILE_CONCAT("net/if_dl.h"    HAVE_NET_IF_DL_H)
  CHECK_INCLUDE_FILE_CONCAT("net/if_arp.h"   HAVE_NET_IF_ARP_H)
ENDIF(UNIX)
IF(WIN32) #Avoid polluting UNIX cmakecache
  CHECK_INCLUDE_FILE_CONCAT("winsock.h"       HAVE_WINSOCK_H)
ENDIF(WIN32)

SET(UUID_HAVES_ALL
  HAVE_STDLIB_H
  HAVE_UNISTD_H
  HAVE_INTTYPES_H
  HAVE_SYS_IOCTL_H
  #HAVE_SYS_TIME_H
  HAVE_SYS_FILE_H
  HAVE_SYS_SOCKET_H
  HAVE_SYS_SOCKIO_H
  HAVE_NET_IF_H
  HAVE_NETINET_IN_H
  HAVE_NET_IF_DL_H
  HAVE_NET_IF_ARP_H
  HAVE_WINSOCK_H
)

SET(UUID_HAVES)
FOREACH(have ${UUID_HAVES_ALL})
  IF(${${have}})
    SET(UUID_HAVES "${UUID_HAVES} -D${have}")
  ENDIF(${${have}})
ENDFOREACH(have)
# Pass all -D :
IF( UUID_HAVES )
SET_SOURCE_FILES_PROPERTIES( ${UUID_SRCS}
  PROPERTIES COMPILE_FLAGS ${UUID_HAVES})
ENDIF( UUID_HAVES )

SET(MANGLE_PREFIX ${UUID_LIBRARY_NAME})
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/uuid_mangle.h.in
               ${CMAKE_CURRENT_BINARY_DIR}/uuid_mangle.h
               @ONLY IMMEDIATE)

# for uuid_mangle.h
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})

ADD_LIBRARY(${UUID_LIBRARY_NAME} ${UUID_SRCS})
SET_TARGET_PROPERTIES(${UUID_LIBRARY_NAME} PROPERTIES ${GDCM_LIBRARY_PROPERTIES})
IF(WIN32 AND NOT CYGWIN)
  TARGET_LINK_LIBRARIES(${UUID_LIBRARY_NAME} iphlpapi)
ENDIF(WIN32 AND NOT CYGWIN)
IF(NOT UUID_INSTALL_NO_LIBRARIES)
  INSTALL(TARGETS ${UUID_LIBRARY_NAME}
    RUNTIME DESTINATION ${UUID_INSTALL_BIN_DIR} COMPONENT Runtime
    LIBRARY DESTINATION ${UUID_INSTALL_LIB_DIR} COMPONENT Runtime
    ARCHIVE DESTINATION ${UUID_INSTALL_LIB_DIR} COMPONENT Development
  ${CPACK_NAMELINK_TYPE}
  )
ENDIF(NOT UUID_INSTALL_NO_LIBRARIES)

